Java Design Pattern Strategy pattern strategy and design pattern Strategy
This chapter describes the knowledge points related to policy patterns in java design patterns.1. Rule mode definition
The rule mode, also known as the algo
of good or bad strategy cases, but the overall old, most of the last century in the 780 's. Given that the book was published in 2011, there is reason to doubt that the author would take his case off, saying only that he was right.
4 Stars | The whole history of business model: a summary of business models that have emerged in the United States, Japan and ChinaThis book outlines the business models that have appeared in the United States, Japan
(system.in); Public String toString (int. finger) {switch (finger) {case 1:return "stone"; Case 2:return "Scissors"; Case 3:return "cloth"; Default:return "Error! "; }} public void Start (Gamestrategy comstrategy) {Boolean gameover = false; while (!gameover) {System.out.println (press ENTER to confirm): 1, Stone, 2, scissors. 3, cloth "); int playerchoice = 0; while (playerchoice The computer's gesture mode inherits from the Ga
Design Pattern-strategy pattern, design pattern-strategy
Rule ModeDefines a series of algorithms, encapsulates each algorithm, and enables them to replace each other. The rule mode allows algorithms to change independently of customers who use it.
Abstract policy role: a policy class, usually implemented by an interf
The main content is about some notes and experiences when learning the design model.
Reference books available
Head first design patterns
Design Patterns: Elements of reusable object-oriented software
Implementation patterns.
The definitions of policy patterns in the two design
Define: define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.I. Strategy Mode
The purpose of the rule mode is to encapsulate each algorithm into an independent class with a common interface for mutual replacement. The policy mode allows the algorithm to change without affecting the client.
Suppose we want
Design Mode (18) Strategy Mode strategy (object behavior type)
1. Overview
Similar situations are often encountered in software development. There are multiple algorithms or policies for implementing a function. We can select different algorithms or policies based on different environments or conditions to complete this function. Such as search and sorting. A c
Design Mode (18) Strategy Mode strategy (object behavior type)
1. Overview
Similar situations are often encountered in software development. There are multiple algorithms or policies for implementing a function. We can select different algorithms or policies based on different environments or conditions to complete the function. Such as search and sorting, a fr
Design Mode (18) Strategy Mode strategy (object behavior type)
1. Overview
Similar situations are often encountered in software development. There are multiple algorithms or policies for implementing a function. We can select different algorithms or policies based on different environments or conditions to complete this function. Such as search and sorting. A c
Mode motiveThere are many different ways to accomplish a task, each of which is called a strategy, and we can choose different strategies to accomplish this task depending on the environment or the conditions.In software development also often encounter similar situation, to achieve a certain function has a number of ways, at this time can use a design mode to make the system can choose the solution flexibl
different actions.
Another less obvious difference is: who promotes behavior changes. In policy mode, the client provides different policies to the context. In state mode, state transfer is managed by the context or State itself. In addition, if you manage state transfer in state, it must hold the reference of context. For example, in the VM example, the State object needs to call the setstate () method of the VM to change its state. On the other hand, stra
The strategy mode is a behavioral design pattern that encapsulates the algorithm one at a time and can use one of the algorithms interchangeably at some point. Conceptually, all of these algorithms are doing the same thing, just realizing the difference.MotivationIn development, we often encounter tasks that are conceptually the same, dealing with different methods, for example, using different tax calculat
. println ("\ n \ N "); 17 18 // Liu Bei is happy, remove the second 19 system. out. println ("-------- Liu Bei is happy, remove the second --------"); 20 context = new context (New givengreenlight (); 21 context. operate (); // executes the second tip 22 system. out. println ("\ n"); 23 24 // What should I do if Sun Quan's sub-troops have followed suit? Remove the third 25 system. out. println ("-------- Sun Quan's small army chased, what should we do, split the third --------"); 26 context = n
"Design pattern Refinement" Learning notes (10) ------Strategy (policy) mode
GoF : Define a series of algorithms, encapsulate them one by one, and allow them to replace each other. This mode allows the algorithm to vary independently from the customer who uses it.
For example, in our system, we need to paint a graphic or a WordArt (such a system is in the real world, a bill output system made by my f
implements strategy{@Override Public voidOperate () {SYSTEM.OUT.PRINTLN ("Paint the Code to red!"); }} class bluepaint implements strategy{@Override Public voidOperate () {SYSTEM.OUT.PRINTLN ("Paint The code to blue!"); }} class Context{ PrivateStrategy strategy; PublicContext (Strategy
Vs 2008
A behavior of a class may have multiple implementation policies. You can extract this behavior and define it as an interface. Then, you can provide multiple implementations of this interface. These classes (Policies) can be replaced with each other without affecting the client.Code.
1. Mode UML diagram
2. Application
Examples of discounts for books are divided into general discount prices and gold discount prices. For book sellers, t
same, because of this equality, can be achieved between the algorithm to replace each other. All strategy algorithms are independent of each other in implementation, and are not dependent on each other.So you can describe this series of strategy algorithms: Policy algorithms are different implementations of the same behavior.the uniqueness of the run-time policy------ during the run, the policy mode can on
8.2.1 Strategy Design pattern (the strategy style)At run time, the policy pattern is useful if the application needs to choose between several algorithms, or between different parts of an algorithm. A common scenario is that when our application needs to perform several tasks, it is different only on very small sub-tasks. Using the policy mode, for the common par
Cache Constructors}Public function Get ($key){Ttserver Cache's Get method implementation}Public function set ($key, $value){Implementation of set method for Ttserver cache}Public Function del ($key){Ttserver Cache's Del method implementation}}--The following policies are used without caching------Class Model{Private $_cache;Public Function __construct (){$this->_cache = new NoCache ();}Public Function Setcache ($cache){$this->_cache = $cache;}}Class Usermodel extends Model{}Class Porductmodel e
GOF "design pattern" is described in the strategy mode:
Define a series of algorithms that encapsulate them one by one and make them interchangeable with each other. The strategy mode allows the algorithm to vary independently from the customer who uses it.
The strategy model is based on the following principles:
1
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.